//
//  NSDictionary+Expand.m
//  KEREN
//
//  Created by chenliang on 2023/8/22.
//

#import "NSDictionary+Expand.h"

@implementation NSDictionary (Expand)

-(float)floatForDict:(NSString *)key{
    id obj = [self objectForKey:key];
    if([obj isKindOfClass:[NSNumber class]]){
        return ((NSNumber *)obj).floatValue;
    }else if([obj isKindOfClass:[NSString class]]){
        return ((NSString *)obj).floatValue;
    }
    return 0.0;
}

-(int)intForDict:(NSString *)key{
    id obj = [self objectForKey:key];
    if([obj isKindOfClass:[NSNumber class]]){
        return ((NSNumber *)obj).intValue;
    }else if([obj isKindOfClass:[NSString class]]){
        return ((NSString *)obj).intValue;
    }
    return 0;
}

-(long long)longlongForDict:(NSString *)key{
    id obj = [self objectForKey:key];
    if([obj isKindOfClass:[NSNumber class]]){
        return ((NSNumber *)obj).longLongValue;
    }else if([obj isKindOfClass:[NSString class]]){
        return ((NSString *)obj).longLongValue;
    }
    return 0;
}

-(NSString *)stringForDict:(NSString *)key{
    id obj = [self objectForKey:key];
    if([obj isKindOfClass:[NSNumber class]]){
        return [NSString stringWithFormat:@"%@",obj];
    }else if([obj isKindOfClass:[NSString class]]){
        return obj;
    }
    return @"";
}

-(NSArray *)arrayForDict:(NSString *)key{
    id obj = [self objectForKey:key];
    if([obj isKindOfClass:[NSArray class]]){
        return obj;
    }
    return [NSArray array];
}

-(NSDictionary *)dictForDict:(NSString *)key{
    id obj = [self objectForKey:key];
    if([obj isKindOfClass:[NSDictionary class]]){
        return obj;
    }
    return nil;
}

@end
